package com.example.haoqisystem.controller;

import com.example.haoqisystem.entity.TrainningApplication;
import com.example.haoqisystem.request.CreateTrainningApplicationRequest;
import com.example.haoqisystem.request.QueryTrainningApplicationListrequest;
import com.example.haoqisystem.request.UpdateTrainningApplicationRequest;
import com.example.haoqisystem.response.BaseResponse;
import com.example.haoqisystem.response.PageResult;
import com.example.haoqisystem.service.TrainningApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "培训申请接口")
@RequestMapping("/trainningApplication")
@RequiredArgsConstructor(onConstructor_ ={@Autowired} )
public class TrainningApplicationController {
    private final TrainningApplicationService trainningApplicationService;

    @ApiOperation("新建培训申请")
    @PostMapping("/add")
    public BaseResponse<TrainningApplication> add(@RequestBody CreateTrainningApplicationRequest request){
        return trainningApplicationService.add(request);
    }

    @ApiOperation("查看培训申请详情")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "申请id",required = true),
            @ApiImplicitParam(name = "deleted",value = "是否已经被逻辑删除",required = true,dataType = "Boolean")
    })
    public BaseResponse<TrainningApplication> detail(Long id,boolean deleted){
        return trainningApplicationService.detail(id,deleted);
    }

    @ApiOperation(value = "编辑培训申请")
    @PutMapping("/update")
    public BaseResponse<TrainningApplication> update(@RequestBody UpdateTrainningApplicationRequest request){
        return trainningApplicationService.update(request);
    }

    @ApiOperation(value = "分页查看培训申请列表")
    @PostMapping("/queryPageList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applicationCompany",value = "申请公司（模糊查询)"),
            @ApiImplicitParam(name = "timeBetween",value = "时间区间(yyyy-MM-dd 至 yyyy-MM-dd"),
            @ApiImplicitParam(name = "deleted",value = "逻辑删除（0 1）",required = true,dataType = "Boolean"),
            @ApiImplicitParam(name = "lectureName",value = "课程名")
    })
    public BaseResponse<PageResult<TrainningApplication>> queryPageList(QueryTrainningApplicationListrequest
                                                                 request){
        return trainningApplicationService.queryList(request);
    }

    @ApiOperation(value = "查看所有培训申请")
    @GetMapping("/queryList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "applicationCompany",value = "申请公司（模糊查询)"),
            @ApiImplicitParam(name = "timeBetween",value = "时间区间(yyyy-MM-dd 至 yyyy-MM-dd"),
            @ApiImplicitParam(name = "deleted",value = "逻辑删除（0 1）",required = true,dataType = "Boolean"),
            @ApiImplicitParam(name = "isGeneratePlan",value = "是否生成培训计划",dataType = "Boolean"),
            @ApiImplicitParam(name = "lectureName",value = "课程名"),
            @ApiImplicitParam(name = "id",value ="id",dataType = "Long")
    })
    public BaseResponse<List<TrainningApplication>> queryList(String applicationCompany,
                                                              String timeBetween,
                                                              Boolean deleted,
                                                              Boolean isGeneratePlan,
                                                              String lectureName,
                                                              Long id){
        return trainningApplicationService.queryList1(applicationCompany,timeBetween,deleted,isGeneratePlan,lectureName,id);
    }

    @ApiOperation(value = "删除培训申请")
    @GetMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "培训申请id",required = true)
    })
    public BaseResponse<String> delete(Long id){
        return trainningApplicationService.delete(id);
    }
}
